package mrtran.iti.vn;

import android.app.Activity;
import android.content.Intent;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.ImageView;

public class SplashScreenActivity extends Activity implements Runnable{
	Thread mThread;
	Runnable mRunnable;
	boolean active = true;
	int mTime=200;
	ImageView logo;
	SoundPool msoPool;
	int soundIntroduce;
	
	
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.splashscreen);
	logo = (ImageView)findViewById(R.id.logo);
	logo.setBackgroundResource(R.drawable.splash);
	
	msoPool = new SoundPool(10,AudioManager.STREAM_MUSIC,0);
	soundIntroduce = msoPool.load(getBaseContext(), R.raw.intro, 1);
}

@Override
protected void onResume() {
	active= true;
	mTime = 200;
	super.onResume();
}

@Override
public void onWindowFocusChanged(boolean hasFocus) {
	if(mThread==null){
		mThread = new Thread(this);
		mThread.start();
	}
	super.onWindowFocusChanged(hasFocus);
}
	public void run() {
		try{
			while(active&&mTime>0){
				mTime-=10;
				mThread.sleep(200);
				msoPool.play(soundIntroduce, 0f, 1.0f, 1, 0, 0.3f);
			}
		}catch(Exception e){}
		finally{
			startActivity(new Intent (getBaseContext(),GameonepieceActivity.class));
			finish();
		}
		
	}
	
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		if(event.getAction()==MotionEvent.ACTION_DOWN){
			active=false;
		}
		return super.onTouchEvent(event);
	}

}
